package main

import (
	"fmt"
	"gin-blog/pkg/setting"
	"gin-blog/routers"
	"net/http"

	"github.com/gin-gonic/gin"
)

func main() {

	router := routers.InitRouter()

	router.GET("/test", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "test",
		})
	})

	s := &http.Server{
		Addr:           fmt.Sprintf(":%d", setting.HTTPPort),
		Handler:        router,
		ReadTimeout:    setting.ReadTimeout,
		WriteTimeout:   setting.WriteTimeout,
		MaxHeaderBytes: 1 << 20,
	}

	s.ListenAndServe()

}

// package main

// import (
// 	"fmt"
// 	"log"
// 	"syscall"

// 	"github.com/fvbock/endless"

// 	"gin-blog/pkg/setting"
// 	"gin-blog/routers"
// )

// func main() {
// 	endless.DefaultReadTimeOut = setting.ReadTimeout
// 	endless.DefaultWriteTimeOut = setting.WriteTimeout
// 	endless.DefaultMaxHeaderBytes = 1 << 20
// 	endPoint := fmt.Sprintf(":%d", setting.HTTPPort)

// 	server := endless.NewServer(endPoint, routers.InitRouter())
// 	server.BeforeBegin = func(add string) {
// 		log.Printf("Actual pid is %d", syscall.Getpid())
// 	}

// 	err := server.ListenAndServe()
// 	if err != nil {
// 		log.Printf("Server err: %v", err)
// 	}
// }
